package com.chijun.mform.full;

import android.content.Context;

import androidx.annotation.NonNull;

import com.chijun.mform.R;
import com.chijun.mform.create.dialog.ISelectProcessPerson;
import com.example.ccj.b.c.custom.tree.TreeMode;
import com.example.ccj.b.c.custom.tree.tree2.TreeStructure2;
import com.example.ccj.b.c.dialog.DialogBase;
import com.example.ccj.u.StringUtils;

import java.util.List;

/**
 * 选择人员dialog
 * 点击ok后返回
 */
public class SelectProcessPersonDialog extends DialogBase {

    private String treeViewName;
    private final ISelectProcessPerson iSelectProcessPerson;
    private final List<String> selectedList;
    private final boolean cnSelectBuMen;
    private TreeStructure2 treeView;
    private List<TreeMode> treeModeList;

    /**
     * 人员通过表单初始化的接口获取
     * @param context 上下文
     * @param treeViewName 抬头名称
     * @param iSelectProcessPerson 选择后的回调
     * @param selectedList 已选中的数据
     * @param cnSelectBuMen 是否可选中部门
     */
    public SelectProcessPersonDialog(@NonNull Context context,
                                     String treeViewName,List<TreeMode> treeModeList,
                                     ISelectProcessPerson iSelectProcessPerson,
                                     List<String> selectedList,
                                     boolean cnSelectBuMen) {
        super(context);
        this.treeViewName = treeViewName;
        this.iSelectProcessPerson = iSelectProcessPerson;
        this.selectedList = selectedList;
        this.cnSelectBuMen = cnSelectBuMen;
        this.treeModeList = treeModeList;
    }

    @Override
    public void onInit() {
        isCanClose(true);
        setLayout(R.layout.dialog_select_person_new);
        setAlpha(1f);//透明度
        isCanClose(true);//点击允许关闭
        isShowBackground(false);//不显示背景
        setShowHeightRatio(true);//按比例显示
        setHeightRatio(0.7);//高度显示比例
        showInBottom();//底部弹出
        setFull(true);//是否铺满
        goneTitleLeftImage();

        treeView = findViewById(R.id.dialog_select_person_tree2);

        if (StringUtils.isEmpty(treeViewName)) treeViewName = "请选择审批人员";
        setTitleCenterText(treeViewName);
        setTitleRightText("OK").setOnClickListener(V->{
            if (iSelectProcessPerson != null) iSelectProcessPerson.onOver(treeView.getSelectedData());
            dismiss();
        });

        setTreeModeList(treeModeList,selectedList,cnSelectBuMen);
    }

    /**
     *
     * @param treeModeList 人员目录
     * @param selectedList 已选中的数据
     * @param cnSelectBuMen 是否可选中部门
     */
    public void setTreeModeList(List<TreeMode> treeModeList,List<String> selectedList,boolean cnSelectBuMen){
        treeView.setCnSelectBuMen(cnSelectBuMen);
        treeView.setData(treeModeList,selectedList);
    }

}
